package snmptest.gateway;

import java.util.List;

import com.isnmp.common.snmp.SNMPAPI;
import com.isnmp.common.snmp.SNMPFactory;
import com.isnmp.common.snmp.SNMPTarget;
import com.isnmp.common.snmp.mib.MibIfEntry;

public class GetObjectTest {
    SNMPAPI snmpapi;
    SNMPTarget nodeParam;

    public GetObjectTest() {
        try {
            SNMPFactory.init(1, null, 8088);

            this.snmpapi = SNMPFactory.getSNMPAPI();

            this.nodeParam = new SNMPTarget();

            this.nodeParam.nodeIP = "172.168.1.82";
            this.nodeParam.port = 161;
            this.nodeParam.readCommunity = "public";
        } catch (Exception ex) {
            ex.printStackTrace();
        }
    }

    public void testGetMibGroup(Object mib) {
        try {
            Object mibobj = this.snmpapi.getMibObject(mib, this.nodeParam);
            System.out.println(mib.getClass());
            System.out.println(mibobj);
            System.out.println("--------------");
        } catch (Exception ex) {
            ex.printStackTrace();
        }
    }

    public void testGetMibTable(Class tableclass) {
        try {
            List list = this.snmpapi.getAllTableData(tableclass, this.nodeParam);
            System.out.println(tableclass + " 表数据个数：" + list.size());
            for (int i = 0; i < list.size(); i++) {
                Object mibobj = list.get(i);
                System.out.println(mibobj);
            }
            System.out.println("--------------");
        } catch (Exception ex) {
            ex.printStackTrace();
        }
    }

    public void testGetOID(String oid) {
        try {
            String s = this.snmpapi.getOIDValue(oid, this.nodeParam);
            System.out.println(oid + "==" + s);
            System.out.println("--------------");
        } catch (Exception ex) {
            ex.printStackTrace();
        }
    }

    public static void main(String[] args) {
        try {
            GetObjectTest test = new GetObjectTest();

            //            test.testGetMibTable(MibIfEntry.class);
            test.testGetOID(".1.3.6.1.2.1.1.1.0");
            System.exit(0);
        } catch (Exception ex) {
            ex.printStackTrace();
        }
    }
}